/*
 * Copyright (c) 2021 Huize (Chengdu) Network Technology Co., LTD All rights reserved.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * huize Service Inc
 * All Rights Reserved @2018
 */
package com.huize.zhike.framework.common.exception;


import com.huize.zhike.framework.common.enumeration.ErrorEnum;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 描述: 业务异常结果类
 *
 * @author tianyuliang
 * @version $Id: BizErrorResult.java, v0.1 2021/2/2
 */
@Getter
@Setter
@NoArgsConstructor
public class BizErrorResult {

    /**
     * 异常code
     */
    private String errCode;

    /**
     * 异常描述
     */
    private String errMsg;

    public BizErrorResult(String errCode, String errMsg) {
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public BizErrorResult(ErrorEnum errorEnum, String errMsg) {
        this.errCode = errorEnum.getCode();
        this.errMsg = errMsg;
    }

    public boolean matchErrorCode(ErrorEnum errorEnum) {
        return this.errCode != null && this.errCode.equalsIgnoreCase(errorEnum.getCode());
    }

    @Override
    public String toString() {
        return String.format("[%s,%s]", getErrCode(), getErrMsg());
    }

}